/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


window.fbAsyncInit = function() {
    
    FB.init({
        appId      : '315241705214029', // App ID
        channelUrl : '//apps.bdnews24.com/fb/channel.html', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        frictionlessRequests : true, //enable frictionless request
        xfbml      : true  // parse XFBML
    });
    
    //remove the scroll bar from canvas
    window.setTimeout(function () {
        FB.Canvas.setAutoGrow()
    }, 250)
    
    //scroll to top after load
    $(function() {
        $('body').scrollTop(0);
    });
    
    //same reason
    $(function() {
        $('<a name="top"/>').insertBefore($('body').children().eq(0));
        window.location.hash = 'top';
    });

    // Additional initialization code here
    
    //find out if the user is logged in
    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            var uid = response.authResponse.userID;
            accessToken = response.authResponse.accessToken;
            
            FB.api('/me', function(info){
                console.log(info);
            //$('#welcome').html("hello there "+info.first_name);
            });
        }else if (response.status === 'not_authorized'){
            //user is in facebook but not in our app
            var oauth_url = 'https://www.facebook.com/dialog/oauth/';
            oauth_url += '?client_id=315241705214029'; //Your Client ID
            oauth_url += '&redirect_uri=' + 'https://apps.facebook.com/bdnews_twenty_four/'; //Send them here if they're not logged in
            oauth_url += '&scope=user_about_me,email,user_location,user_photos,publish_actions,user_birthday,user_likes';

            window.top.location = oauth_url;
        }else {
            window.top.location = 'https://www.facebook.com/index.php';
        }
    });
};

function requestToFriends() {
    FB.ui({
        method: 'apprequests',
        title: 'BdNews24 Request',
        message: 'Join us and be a part of the BdNews24!'
    }); // Call to FB.ui
} // messageToFriend





// Load the SDK Asynchronously
(function(d){
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {
        return;
    }
    js = d.createElement('script');
    js.id = id;
    js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    ref.parentNode.insertBefore(js, ref);
}(document));
